package com.bangdream.michelia.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.bangdream.michelia.R;

//首页我的中的列表点击项适配器
public class MainItemMyListAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private LayoutInflater layoutInflater;
    private String[] stNames = {"我的证书","资料设置","关于我们"};//,"软件更新"
    private int[] nmIcons = {R.mipmap.icon_my_item1,R.mipmap.icon_my_item3,R.mipmap.icon_my_item4};//,R.mipmap.icon_my_item5
    private OnRecycleItemClick onRecycleItemClick;

    public OnRecycleItemClick getOnRecycleItemClick() {
        return onRecycleItemClick;
    }

    public void setOnRecycleItemClick(OnRecycleItemClick onRecycleItemClick) {
        this.onRecycleItemClick = onRecycleItemClick;
    }

    public interface OnRecycleItemClick{
        void onMyItemClick(int position);
    }
    public MainItemMyListAdapter(Context mContext) {
        this.mContext = mContext;
        layoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.main_item_my_adapter_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = null;
        if(holder instanceof ViewHolder){
            viewHolder = (ViewHolder) holder;
            viewHolder.tvText.setText(stNames[position]);
            viewHolder.ivIcon.setImageResource(nmIcons[position]);
            viewHolder.poistion = position;
        }
    }

    @Override
    public int getItemCount() {
        return stNames==null?0:stNames.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView ivIcon;
        private TextView tvText;
        private int poistion;
        public ViewHolder(View itemView) {
            super(itemView);
            ivIcon = itemView.findViewById(R.id.ivIcon);
            tvText = itemView.findViewById(R.id.tvText);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(onRecycleItemClick!=null){
                        onRecycleItemClick.onMyItemClick(poistion);
                    }
                }
            });
        }
    }
}
